package com.tb.controller;

import com.tb.pojo.Clazz;
import com.tb.pojo.College;
import com.tb.pojo.Profession;
import com.tb.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/info")
public class InformationController {

    @Autowired
    private InfoService is;


    /**
     * 获取学院信息
     * @param model 返回的学院信息
     * @return
     */
    @GetMapping("/getCollege")
    public String getCollege(Model model) {
        List<College> collegeList = is.findCollege();
        model.addAttribute("collegeList", collegeList);
        return "/student/register";

    }


    /**
     * 获取college的json对象
     * @return
     */
    @GetMapping("/getColleges")
    @ResponseBody
    public List<College> getColleges() {
        return  is.findCollege();
    }

    /**
     * 根据collegeId 获取 对应学院的专业信息
     * @param collegeId 需要查询专业的学院的id
     * @return
     */
    @GetMapping("/getProfessions")
    @ResponseBody
    public Map<String, String> getProfessions(@RequestParam(value = "collegeId") int collegeId) {

        return is.getProfessions(collegeId);
    }


    /**
     * 根据学院id获取对应的专业信息
     * @param collegeId 传入的学院id
     * @return
     */
    @GetMapping("/getProfession")
    @ResponseBody
    public List<Profession> getProfession(@RequestParam("collegeId") int collegeId) {

        return is.findProfession(collegeId);
    }


    /**
     * 根据专业信息返回相应的班级信息
     * @param professionId 传入的专业信息
     * @return
     */
    @GetMapping("/getClazz")
    @ResponseBody
    public List<Clazz> getClazz(@RequestParam("professionId") int professionId) {
        return is.findClazz(professionId);
    }

}
